#include "AssetData.h"

static const AssetType g_UnknownAssetType = "UnknownAssetType";

const AssetType & AssetData::GetAssetType()
{
	return g_UnknownAssetType;
}
AssetDataList AssetData::GetChildrenByType(const AssetType & type)
{
	AssetDataList::iterator i = m_Children.begin();
	AssetDataList List;
	while(i != m_Children.end())
	{
		if((*i)->GetAssetType() == type)
		{
			List.push_back(*i);
		}
		++i;
	}
	return List;
}
AssetDataPtr AssetData::GetParent()
{
	return m_pParent.lock();
}

const RE_String AssetData::GetName()
{
	return m_name;
}


bool AssetData::Restore()
{

	return true;
}

bool AssetData::RestoreChildren()
{
	AssetDataList::iterator i = m_Children.begin();
	AssetDataList::iterator end = m_Children.end();
	while(i != end)
	{
		if(i->get()->Restore())
		{
			if(!i->get()->RestoreChildren())
			{
				return false;
			}
		}else
		{
			return false;
		}
		++i;
	}
	return true;
}


bool AssetData::Release()
{
	return true;
}
void AssetData::RemoveChildren()
{
	AssetDataList::iterator i = m_Children.begin();
	while( i != m_Children.end())
	{
		(*i)->RemoveChildren();
		++i;
	}
	m_Children.clear();
}
void AssetData::SetParent(AssetDataPtr parent)
{
	m_pParent = parent;
}
void AssetData::AddChild(AssetDataPtr child)
{
	m_Children.push_back(child);
}

AssetDataPtr AssetData::TraceParent(const AssetType & type)
{
	AssetDataPtr asset = GetParent();
	while(asset != AssetDataPtr())
	{
		if(asset->GetAssetType() == type)
		{
			return asset;
		}
		asset = asset->GetParent();
	}
	return AssetDataPtr();
}